from django.shortcuts import render
from .models import *
from django.http import HttpResponse
# Create your views here.
def index(request):
    if request.method =='GET':
        return render(request,'zhuce.html')
    else:
        sname = request.POST.get('sname','')
        cname = request.POST.get('clsname','')
        cournames = request.POST.getlist('coursename',[])
        #将数据注册到数据库
        flag = zhuceshuji(sname,cname,*cournames)
        if flag:
            return HttpResponse('注册成功')

        return HttpResponse('注册失败')

def show(request):
    all = Clazz.objects.all()
    return render(request,'showall.html',{'all':all})

#显示当前班级的所有学生信息
def getstu(request):
    #拿到班级编号
    cno= request.GET.get('cno','')
    no = int(cno)
    # 根据班级查询所有学生信息
    stu = Clazz.objects.get(cno=no).student_set.all()

    return render(request,'getstu.html',{'stu':stu})